package com.niit.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.niit.util.JDBCUtil;

public class UserDao {

	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet res = null;

	
	public UserDao() {
		conn = JDBCUtil.getConnection();
	}

	
	public boolean login(String username, String password) {
		boolean flag = false;
		try {
			String sql = "select * from user where username = ? and password = ?";
			ps = conn.prepareStatement(sql);
			ps.setString(1, username);
			ps.setString(2, password);
			res = ps.executeQuery();
			int count = 0;
			while (res.next()) {
				count++;
			}
			if (count == 1) {
				flag = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.closeDB(conn, ps, res);
		}
		return flag;
	}

}
